package com.kk.nb_policy.controller.app;

import com.kk.nb_policy.service.PolicyInsuranceService;
import com.woniuxy.boot.common.bean.PolicyInsurance;
import com.woniuxy.boot.common.pojo.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: K
 * @Date: 2024/12/18
 */
@RestController("appPolicyInsuranceController")
@RequestMapping("app/policyInsurance")
public class PolicyInsuranceController {
    @Autowired
    private PolicyInsuranceService policyInsuranceService;

    @PostMapping("add")
    ResultObj addPolicyInsurance(@RequestBody PolicyInsurance policyInsurance) {
        List<Long> insuranceIds = policyInsurance.getInsuranceIds();
        for (Long insuranceId : insuranceIds) {
            com.kk.nb_policy.bean.PolicyInsurance policyInsurance1 = new com.kk.nb_policy.bean.PolicyInsurance();
            policyInsurance1.setInsuranceId(insuranceId);
            policyInsurance1.setPolicyId(policyInsurance.getPolicyId());
            policyInsuranceService.save(policyInsurance1);
        }
        return ResultObj.ok();
    }
}

